package tests;

import static org.junit.Assert.*;

import java.util.ArrayList;

import modelLayer.Clothing;
import modelLayer.Equipment;
import modelLayer.GunReplicas;
import modelLayer.Product;
import modelLayer.Supplier;

import org.junit.Test;

import dbLayer.DbPartner;
import dbLayer.DbProduct;


public class TestDbProduct {

	@Test
	public void retrieveAllProductsTest() {
		DbProduct dbper = new DbProduct();
		try{
			ArrayList <Product> proList = dbper.retrieveAllProducts();
			if(proList.size() > 0)
				System.out.println("Product list working.");
		}catch(Exception e){
			fail("Cant get all products list.");
		}
	}
	
	@Test
	public void retrieveAllClothingTest(){
		DbProduct dbper = new DbProduct();
		try{
			ArrayList<Clothing> proList = dbper.retrieveAllClothing();
			if(proList.size() > 0)
				System.out.println("Clothing list working.");
		}catch(Exception e){
			fail("Cant get clothing list.");
		}
	}
	
	@Test
	public void retrieveAllEquipmentTest(){
		DbProduct dbper = new DbProduct();
		try{
			ArrayList<Equipment> proList = dbper.retrieveAllEquipment();
			if(proList.size() > 0)
				System.out.println("Equipment list working");
		}catch(Exception e){
			fail("Cant get equipment list.");
		}
	}

	@Test
	public void retrieveAllGunReplicas(){
		DbProduct dbper = new DbProduct();
		try{
			ArrayList<GunReplicas> proList = dbper.retrieveAllGunReplicas();
			if(proList.size() > 0)
				System.out.println("Gun Replicas list is working.");
		}catch(Exception e){
			fail("Cant get gunreplicas list.");
		}
	}

	@Test
	public void insertProductTest(){
		DbProduct dbper = new DbProduct();
		Clothing cloth = new Clothing();
		DbPartner dbp = new DbPartner();
		Supplier supObj = dbp.retrieveSupplierFromDb(1);
		cloth.setName("Hotpants");
		cloth.setPurchasePrice(100);
		cloth.setSalesPrice(200);
		cloth.setRentPrice(50);
		cloth.setCountryOfOri("USA");
		cloth.setMinStock(10);
		cloth.setColor("Navy blue");
		cloth.setSize("XS");
		cloth.setSupplier(supObj);
		try{
			dbper.insertProduct(cloth);
			System.out.println("Cloth inserted.");
		}catch(Exception e){
			fail("Cloth not inserted.");
		}
	}
	
	@Test
	public void updateProductTest(){
		DbProduct dbper = new DbProduct();
		Clothing cloth = new Clothing();
		cloth.setName("Notpants");
		cloth.setPurchasePrice(100);
		cloth.setSalesPrice(200);
		cloth.setRentPrice(50);
		cloth.setCountryOfOri("China");
		cloth.setMinStock(10);
		cloth.setColor("Navy blue");
		cloth.setSize("XS");
		cloth.setProductId(14);
		try{
			dbper.updateProduct(cloth);
			System.out.println("Cloth obj updated.");
		}catch(Exception e){
			fail("Cloth obj not updated.");
		}
	}
	
	@Test
	public void deleteProductTest(){
		DbProduct dbper = new DbProduct();
		try{
			dbper.deleteProduct(14);
			System.out.println("Obj is deleted.");
		}catch(Exception e){
			fail("Obj not deleted.");
		}
	}
}
